package com.niuwa.p2p.utils.schedule;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.quartz.JobExecutionContext;
import org.apache.log4j.Logger;

import com.niuwa.p2p.core.utils.ApplicationContextUtil;

/*
 * 
 * @title 通过反射进行映射
 *
 * @author tennyqin 
 * @version 1.0
 * @created 2015年3月26日
 */
public class BeanJob extends AbstractEdiJob {

	public final Logger logger = Logger.getLogger(this.getClass());

	@Override
	public boolean exeucuteInternal(JobExecutionContext context){
		Object obj = ApplicationContextUtil.getApplicationContext().getBean(jobEntity.getSpringId()); //job1 or job2
		try {
			Method method = obj.getClass().getMethod(jobEntity.getJobMethod()); //run or test
			method.invoke(obj);
		} catch (SecurityException e) {
			logger.error("error", e);
			return false;
		} catch (NoSuchMethodException e) {
			logger.error("error", e);
			return false;
		} catch (IllegalArgumentException e) {
			logger.error("error", e);
			return false;
		} catch (IllegalAccessException e) {
			logger.error("error", e);
			return false;
		} catch (InvocationTargetException e) {
			logger.error("error", e);
			return false;
		}
		return true;
	}
}
